<%-- 
    Document   : sites
    Created on : Nov 24, 2010, 12:49:37 AM
    Author     : navneet
--%>
<%@page import="com.myapp.global.ConnectionBean"%>
<%@page import="com.myapp.global.user_listclass"%>
<%@page import="java.sql.ResultSet"%>

<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%
    user_listclass ulc = new user_listclass();
%>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Web-Dev-Tool by Navneet Kumar</title>
        <meta http-equiv="Content-Language" content="English" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
        <link rel="stylesheet" type="text/css" href="css/style1.css" media="screen" />
        <script type="text/javascript" src="js/javascript4.js" ></script>
        <script type="text/javascript" src="js/javascript_front2.js" ></script>
        <script type="text/javascript">
            var page        = 1;
            var sortby      = 1;
            var sortas      = 1;
            var search      = 0;
            var searchfor   = 0;
            document.onloaded = getoverview();

            function getoverview(){
                var params = '';
                params += '&page='+page;
                params += '&sortby='+sortby;
                params += '&sortas='+sortas;
                params += '&search='+search;
                params += '&searchfor='+searchfor;
                getaddon("ajax/common.jsp?","doOn=sites&doThis=1"+params,"tabs","getoverview_cbk");
            }
            function getoverview_cbk()
            {
                //getObject("neetProcessingDivtabsData").style.display = 'none';
            }
            function getGroupCompanies(id)
            {
                getObject("neetProcessingDivGroupedComp").style.display = '';
                getaddon("ajax/common.jsp?","doOn=sites&doThis=2&GroupFilter="+id,"companyCombo_div","getGrpComp_cbk");
            }

            function getGrpComp_cbk()
            {
                getObject("neetProcessingDivGroupedComp").style.display = 'none';
            }
        </script>
     </head>
    <body>
        <div id="wrap">
            <jsp:include page="/WEB-INF/jspf/header.jspf" flush="true" ></jsp:include>
            <div id="right">
                <%
                    if(session.getAttribute("currentUser") != null && session.getAttribute("currentUser").equals("admin")){
                        if(session.getAttribute("currentAction") != null && session.getAttribute("currentAction").equals("EditSite"))
                        {
                            String SiteId     = (String)session.getAttribute("SiteId");
                            ConnectionBean cb = new ConnectionBean(true);
                            String Query      = "SELECT `id`,`group_id`,`company_id`,`site_name`,`description` FROM "
                                              + "`sites` WHERE `id`="+SiteId;
                            int id            = -1,
                                    group_id  = -1,
                                   company_id = -1;
                            String  site_name = "",
                                  description = "";
                            cb._executeQuery(Query);
                            if(cb.rs.next()){
                                id              = cb.rs.getInt("id");
                                group_id        = cb.rs.getInt("group_id");
                                company_id      = cb.rs.getInt("company_id");
                                site_name       = cb.rs.getString("site_name");
                                description     = cb.rs.getString("description");
                            }
                            //out.println(Query+"<br/>"+id+" "+group_id+""+company_name+""+description);
                %>
                <h1>Edit Site</h1>
                <html:form action="/editSite">
                    <html:hidden property="id" value="<%=String.valueOf(id) %>" ></html:hidden>
                    <table>
                        <tbody>
                            <tr>
                                <td>Group Name:</td><td><%= ulc.getAllGroups_Combo("groupId","","onchange='getGroupCompanies(this.value);'",String.valueOf(group_id)) %></td>
                            </tr>
                            <tr>
                                <td>Company Name:</td>
                                <td>
                                    <div id="neetProcessingDivGroupedComp" style='position:relative;display:none;'>
                                        <div style='position:absolute; top:0%; left:50%;'>
                                            <img alt=""  src='Image/icon_processing.gif' />
                                        </div>
                                    </div>
                                    <div id="companyCombo_div">
                                        <%= ulc.getAllCompanies_Combo("companyId","","",String.valueOf(company_id)) %>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>Site Name:</td><td><html:text property="siteName" value="<%=site_name %>" /></td>
                            </tr>
                            <tr>
                                <td>Description:</td><td><html:text property="description" value="<%=description %>" /></td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center"><html:submit title='Edit Site'>Edit Site</html:submit></td>
                            </tr>
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="2" align="left">
                                    <span style='color:red'>
                                        <bean:write name="ECAFB" property="error" ignore="true" /><br/>
                                        <html:errors property="groupId" /><br/>
                                    </span>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </html:form>
                <%
                    }
                    else
                    {
                %>
                <h1>Add Site</h1>
                <html:form action="/addSite">
                    <table>
                        <tbody>
                            <tr>
                                <td>Group Name:</td><td><%= ulc.getAllGroups_Combo("groupId","","onchange='getGroupCompanies(this.value);'","") %></td>
                            </tr>
                            <tr>
                                <td>Company Name:</td>
                                <td>
                                    <div id="companyCombo_div">
                                        <div id="neetProcessingDivGroupedComp" style='position:relative;display:none;'>
                                            <div style='position:absolute; top:0%; left:50%;'>
                                                <img alt=""  src='Image/icon_processing.gif' />
                                            </div>
                                        </div>
                                        <%= ulc.getAllCompanies_Combo("companyId","","","") %>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>Site Name:</td><td><html:text property="siteName" /></td>
                            </tr>
                            <tr>
                                <td>Description:</td><td><html:text property="description" /></td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center"><html:submit title='Add Site'>Add Site</html:submit></td>
                            </tr>
                        </tbody>
                        <tfoot>
                            <tr>
                                <td colspan="2" align="left">
                                    <span style='color:red'>
                                        <bean:write name="ASAFB" property="error" ignore="true" /><br/>
                                        <html:errors property="groupId" /><br/>
                                        <html:errors property="companyId" /><br/>
                                        <html:errors property="siteName" /><br/>
                                    </span>
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                </html:form>
                <%
                    }
                %>
                <div id="messageSites">
                    <% if(session.getAttribute("messageSiteDelete") != null){
                            out.println(session.getAttribute("messageSiteDelete"));
                        }
                    %>
                </div>
                <br/>
                <div id="tabs">
                    <div id="neetProcessingDivtabsData" style='position:relative;'>
                        <div style='position:absolute; top:0%; left:50%;'>
                            <img alt=""  src='Image/icon_processing.gif' />
                        </div>
                    </div>
                </div>
                <%
                }
                else
                {
            %>
                    <jsp:include page="login.jsp" flush="true" ></jsp:include>
            <%
                }
            %>
        </div>
        <div id="left">
            <%
            //if(session.getAttribute("currentUser") != null){
            %>
                <jsp:include page="/WEB-INF/jspf/left_menu.jspf" flush="true" ></jsp:include>
            <%
            //}
            %>
        </div>
        <div style="clear: both;"> </div>
        <jsp:include page="/WEB-INF/jspf/footer.jspf" flush="true" ></jsp:include>
    </div>
    </body>
</html>